import { Variable } from "@/api/interface/iot";
// import { getEventList } from "@/api/modules/airoom/event";
import { getDeviceListAll } from "@/api/modules/iot/device";
import { EventDetail, useVideo } from "../../hooks/useVideo";
import "../../index.scss";
import { EventInfo } from "../../interface";
import DialogBox from "@/components/DialogBox";
export default defineComponent({
	emits: ["lastAi"],
	setup(props, { emit }) {
		const route = useRoute();
		let { getAiLabel } = useVideo();
		const state = reactive({
			dictMap: {} as { [key: string]: string },
			eventList: [] as EventInfo[],
			deviceList: [] as any,
			refresh: {} as NodeJS.Timeout | any,
			eventInfo: {} as EventInfo | any,
			variableList: [] as Variable.ResVariable[]
		});
		const featch = async () => {
			clearRefresh();
			// let res: any = await getEventList({
			// 	sns: state.deviceList.map(item => item.sn).join(","),
			// 	pageIndex: 1,
			// 	pageSize: 50
			// });
			state.eventList = [
				{
					id: "e2bcf92cdd654c1ba020bff688a1409c",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[276,52,287,68],"probs":81},{"area":[204,62,215,75],"probs":81},{"area":[170,51,177,60],"probs":73}]},"image":["1/1/1412785219289072_003_2023-12-26 00:57:05_20231226085706000.jpg"],"timestamp":1703552226141}',
					remark: "AI事件",
					createTime: "2023-12-26 08:57:06",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "1149da03d6864881aa7cfccde6bf2ac2",
					devSn: "1412785219289072_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[269,9,285,28],"probs":88}]},"image":["1/1/1412785219289072_004_2023-12-26 00:25:59_20231226082559000.jpg"],"timestamp":1703550359927}',
					remark: "AI事件",
					createTime: "2023-12-26 08:26:00",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "441f9620e36040f499b160c863c493d3",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[113,57,124,70],"probs":84}]},"image":["1/1/1412785219289072_003_2023-12-26 00:19:43_20231226081944000.jpg"],"timestamp":1703549984226}',
					remark: "AI事件",
					createTime: "2023-12-26 08:19:44",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "3acb6a04429f46f99fd955e6e92b6e16",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[123,56,133,69],"probs":83}]},"image":["1/1/1412785219289072_003_2023-12-25 23:54:47_20231226075447000.jpg"],"timestamp":1703548487416}',
					remark: "AI事件",
					createTime: "2023-12-26 07:54:47",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "61c6e6abb4ce4696bedfc3151a777c9c",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[496,50,505,61],"probs":75}]},"image":["1/1/1412785219289072_005_2023-12-25 23:48:31_20231226074831000.jpg"],"timestamp":1703548111841}',
					remark: "AI事件",
					createTime: "2023-12-26 07:48:32",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "bab52e7324dd41038f7cc8b7ade24f52",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[189,33,198,43],"probs":61}]},"image":["1/1/1412785219289072_003_2023-12-25 21:37:27_20231226053727000.jpg"],"timestamp":1703540247872}',
					remark: "AI事件",
					createTime: "2023-12-26 05:37:28",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "b259bd78e3e8490ea2f4d7757bbd0e78",
					devSn: "1412785219289072_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[311,67,336,99],"probs":84}]},"image":["1/1/1412785219289072_004_2023-12-25 20:22:37_20231226042237000.jpg"],"timestamp":1703535757281}',
					remark: "AI事件",
					createTime: "2023-12-26 04:22:37",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "b70ca800e86d49a5bf5700068d626e69",
					devSn: "A34F08C0AB8B",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 02:03:04",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "d30bc8b7a4b24540865bdaf96fb6dafb",
					devSn: "A34F08C0AB8C",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 02:00:17",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "c2a8667b7d294db5a35c459e7296be4a",
					devSn: "7605662860169526_005",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:39",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "c93a7564390a41db91acde02a625140c",
					devSn: "7605662860169526_007",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:39",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "02b5abd771c64e6589769ad28b19b574",
					devSn: "7605662860169526_008",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:39",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "c179e087a03846bfbf56c4ef5415bb69",
					devSn: "7605662860169526_003",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:39",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "59b79db347404630833c89868eb3d46e",
					devSn: "7605662860169526_004",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:38",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "06ad9be664b744689104a98053830e07",
					devSn: "7605662860169526_006",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:38",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "de54d3fdaa354b7396b6f3d327807767",
					devSn: "7605662860169526_001",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:38",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "e4b65095fc034b218b1a3f6af31f9553",
					devSn: "30e78cf2ffa414d3MS",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:38",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "c5d3d518a8c84b618abe5f27249a0d25",
					devSn: "7605662860169526_002",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-26 01:59:38",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "7313b963d4fc4716aaba13bf1e630405",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[229,48,239,59],"probs":76}]},"image":["1/1/1412785219289072_003_2023-12-25 16:00:28_20231226000029000.jpg"],"timestamp":1703520029350}',
					remark: "AI事件",
					createTime: "2023-12-26 00:00:29",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "0efe7c528364481289226d38ccba48ea",
					devSn: "2846039196029599_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"motion":[{"area":[0,0,1,1],"probs":100}]},"image":["1/1/2846039196029599_004_2023-12-25 15:29:12_20231225232913000.jpg"],"timestamp":1703518153065}',
					remark: "AI事件",
					createTime: "2023-12-25 23:29:13",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "d28d167b3cb045c38d27d8174b8e9290",
					devSn: "1412785219289072_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[342,27,359,48],"probs":82}]},"image":["1/1/1412785219289072_004_2023-12-25 15:04:15_20231225230415000.jpg"],"timestamp":1703516655423}',
					remark: "AI事件",
					createTime: "2023-12-25 23:04:15",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "88072191662e4b208d4a949d983b7117",
					devSn: "A34F08C0AB8B",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:35:59",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "409fd6c642514353b8c0835ae2083def",
					devSn: "7605662860169526_001",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:17",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "c21ddeb5d3074c15a0e116cf4b5ee9ef",
					devSn: "7605662860169526_002",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:17",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "3b201912f45e4ab4bbbb25cdc219ebf8",
					devSn: "7605662860169526_006",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:17",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "f60b58e3291e429b8a10ccc8ca2ae822",
					devSn: "7605662860169526_008",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:17",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "1bf1e0cf8cc6442eaa97e676840ce1b9",
					devSn: "7605662860169526_003",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:17",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "567bf484d9934d788e42a384612085a6",
					devSn: "7605662860169526_005",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:16",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "5ec37248a001458680b7c9c6f4fed4a9",
					devSn: "30e78cf2ffa414d3MS",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:16",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "cdf0a9ddb12c40058a74f7313a77339f",
					devSn: "7605662860169526_007",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:16",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "3805a56dae8b4c9ea326fa27a85e57d2",
					devSn: "7605662860169526_004",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:16",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "a8175098457148e988b6c193ff7545c4",
					devSn: "A34F08C0AB8C",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:10",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "b17649daf32c44159a69839843501910",
					devSn: "30e78cf2ffa414d3MS",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 22:33:07",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "cf21c59b49c74fb7a5c019f41fb3a07d",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[339,48,348,58],"probs":71}]},"image":["1/1/1412785219289072_005_2023-12-25 13:42:45_20231225214246000.jpg"],"timestamp":1703511766007}',
					remark: "AI事件",
					createTime: "2023-12-25 21:42:46",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "2ba74452c505496abdefab16cd4187e7",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[155,67,164,78],"probs":77},{"area":[65,153,80,169],"probs":85}]},"image":["1/1/1412785219289072_005_2023-12-25 13:36:26_20231225213626000.jpg"],"timestamp":1703511386267}',
					remark: "AI事件",
					createTime: "2023-12-25 21:36:26",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "bae5fc2cde7a4effa903f65c080659a9",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[279,57,294,74],"probs":78}]},"image":["1/1/1412785219289072_003_2023-12-25 13:23:50_20231225212350000.jpg"],"timestamp":1703510630330}',
					remark: "AI事件",
					createTime: "2023-12-25 21:23:50",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "e76cea782b8b4f75818ffb2a35f47470",
					devSn: "1412785219289072_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[266,0,278,12],"probs":76}]},"image":["1/1/1412785219289072_004_2023-12-25 11:37:02_20231225193702000.jpg"],"timestamp":1703504222040}',
					remark: "AI事件",
					createTime: "2023-12-25 19:37:02",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "62db79338d074a6ab235d3770641f7d7",
					devSn: "1412785219289072_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[343,52,366,81],"probs":90}]},"image":["1/1/1412785219289072_004_2023-12-25 11:30:43_20231225193043000.jpg"],"timestamp":1703503843687}',
					remark: "AI事件",
					createTime: "2023-12-25 19:30:43",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "91225ca63c9f4fa2a897fb272bcf18d9",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[302,70,318,88],"probs":78},{"area":[353,61,368,77],"probs":73}]},"image":["1/1/1412785219289072_003_2023-12-25 11:18:00_20231225191800000.jpg"],"timestamp":1703503080844}',
					remark: "AI事件",
					createTime: "2023-12-25 19:18:01",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "04a9664e07d040048ce206505d5fc974",
					devSn: "1412785219289072_004",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[366,15,381,34],"probs":85}]},"image":["1/1/1412785219289072_004_2023-12-25 11:11:40_20231225191141000.jpg"],"timestamp":1703502701206}',
					remark: "AI事件",
					createTime: "2023-12-25 19:11:41",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "78334bd5e9e646aab0f418bb232c90be",
					devSn: "2846039196029599_002",
					type: "",
					key: "alarm",
					value:
						'{"event":{"headCount":[{"area":[0,0,0,0],"probs":100}]},"image":["1/1/2846039196029599_002_2023-12-25 11:11:39_20231225191140000.jpg"],"timestamp":1703502700791}',
					remark: "AI事件",
					createTime: "2023-12-25 19:11:41",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "0fedf8392c9d4908a77a3a0c10e6c040",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[12,131,29,151],"probs":81}]},"image":["1/1/1412785219289072_005_2023-12-25 11:11:39_20231225191140000.jpg"],"timestamp":1703502700430}',
					remark: "AI事件",
					createTime: "2023-12-25 19:11:40",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "760584b677784be0957e622e35bad3d1",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[183,66,192,77],"probs":65},{"area":[605,89,618,104],"probs":62}]},"image":["1/1/1412785219289072_005_2023-12-25 11:05:20_20231225190520000.jpg"],"timestamp":1703502320335}',
					remark: "AI事件",
					createTime: "2023-12-25 19:05:20",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "6edcc7c5cb8a4e78a86c4ddc6f5d699c",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[599,103,613,120],"probs":80}]},"image":["1/1/1412785219289072_005_2023-12-25 10:52:40_20231225185240000.jpg"],"timestamp":1703501560488}',
					remark: "AI事件",
					createTime: "2023-12-25 18:52:40",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "9d1c8d7420c84936b522143ab93a718c",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[144,64,153,75],"probs":79},{"area":[485,82,499,99],"probs":70},{"area":[540,91,555,109],"probs":65},{"area":[499,68,512,83],"probs":76}]},"image":["1/1/1412785219289072_003_2023-12-25 10:40:07_20231225184008000.jpg"],"timestamp":1703500807950}',
					remark: "AI事件",
					createTime: "2023-12-25 18:40:08",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "6fb1531c5cca45828a5c4f16fde66597",
					devSn: "1412785219289072_005",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[206,118,227,144],"probs":72}]},"image":["1/1/1412785219289072_005_2023-12-25 09:56:21_20231225175623000.jpg"],"timestamp":1703498182162}',
					remark: "AI事件",
					createTime: "2023-12-25 17:56:23",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "497aff73a1ca4f96820d71cf5267ab7b",
					devSn: "1412785219289072_003",
					type: "",
					key: "alarm",
					value:
						'{"event":{"no_helmet":[{"area":[189,69,203,84],"probs":66},{"area":[343,51,353,63],"probs":75},{"area":[299,53,309,63],"probs":78}]},"image":["1/1/1412785219289072_003_2023-12-25 09:56:20_20231225175622000.jpg"],"timestamp":1703498181984}',
					remark: "AI事件",
					createTime: "2023-12-25 17:56:22",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "6713b3bfba934f0899a424b4f1eb9f6b",
					devSn: "A34F08C0AB8B",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 17:33:51",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "6d47a0c34160454199fcfa64bbf9d6fe",
					devSn: "A34F08C0AB8C",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 17:31:39",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				},
				{
					id: "2931f7c6f5144b6e98df0b663588f254",
					devSn: "7605662860169526_007",
					type: "",
					key: "login",
					value: "login",
					remark: "设备上线",
					createTime: "2023-12-25 17:31:34",
					devName: "",
					keyName: "",
					valueType: "",
					valueUnit: ""
				}
			];
			state.eventInfo = state.eventList[0] || {};
			emit(
				"lastAi",
				state.eventList.find(item => item.remark == "AI事件")
			);
			state.refresh = setTimeout(async () => {
				if (!route.path.includes("/home") && !route.path.includes("/topo") && !route.path.includes("/preview")) {
					return;
				}
				await featch();
			}, 30000);
		};
		const clearRefresh = () => {
			if (state.refresh) {
				clearTimeout(state.refresh);
				state.refresh = null;
			}
		};
		onMounted(() => {
			//获取设备列表
			getDeviceListAll({ pageIndex: 1, pageSize: 9999, deptId: "" }).then(res => {
				state.deviceList = res.result?.records || [];
				featch();
			});
		});
		const detailDialog = reactive({
			visible: false,
			title: "事件详情",
			detail: {} as EventInfo
		});
		const featchDetail = (item: EventInfo) => {
			detailDialog.visible = true;
			detailDialog.detail = item;
		};
		return () => {
			return (
				<div class="w-full right-event item-container">
					<DialogBox
						width={detailDialog.detail.remark == EVENT_AI ? "700px" : "85vw"}
						footerLabel={["确定"]}
						title={detailDialog.title}
						v-model:visible={detailDialog.visible}
						onClose={() => (detailDialog.visible = false)}
					>
						{detailDialog.visible ? <EventDetailChild eventInfo={detailDialog.detail} /> : null}
					</DialogBox>
					<div class="title">实时事件</div>
					<el-scrollbar class="data-list" style="height: calc(100% - 45px);">
						{!state.eventList?.length ? <div class="p-4">暂无事件记录</div> : null}
						{state.eventList?.map((item: any) => {
							return (
								<div class="event-item flex justify-between" onClick={() => featchDetail(item)}>
									<div
										class={[
											"event-tag",
											item.remark == "AI事件"
												? "ai"
												: item.remark == "设备上线"
												? "login"
												: item.remark == "设备下线"
												? "logout"
												: "alarm"
										]}
									>
										{item.remark}
									</div>
									<div class="text">
										{item.remark == "AI事件" ? getAiLabel(item) : (item.devName || item.devSn) + item.remark.replace("设备", "")}
									</div>
									<div class="time">{item.createTime}</div>
								</div>
							);
						})}
					</el-scrollbar>
				</div>
			);
		};
	}
});

// import { getAiList } from "@/api/modules/video";
import { filePrefix } from "@/hooks/useSystem";
import "../event.scss";
import { PropType } from "vue";
import { dayjs } from "element-plus";
import { useRoute } from "vue-router";
import AirConditioner1Img from "@/assets/images/iot/device/deviceInfo/airConditioner1.png";
const EVENT_AI = "AI事件";
const EventDetailChild = defineComponent({
	props: {
		eventInfo: {
			type: Object as PropType<EventInfo>,
			default() {
				return {};
			}
		}
	},
	emits: [],
	setup(props) {
		let { dictMap, getAiInfo } = useVideo();
		const state = reactive({
			aiInfo: {} as EventDetail,
			dictMap: dictMap,
			productList: useVideo().videoProducts,
			view: "image" as "chart" | "image",
			imgList: []
		});
		onMounted(() => {
			loadData();
		});
		const loadData = async () => {
			if (props.eventInfo.remark == EVENT_AI) {
				//AI详情
				state.aiInfo = getAiInfo(props.eventInfo.value);
			} else {
				//AI图片列表
				state.view = "image";
				await loadImage();
			}
		};
		const loadImage = async () => {
			// let { result }: any = await getAiList(
			// 	{
			// 		pageIndex: 1,
			// 		pageSize: 8,
			// 		key: "alarm",
			// 		keyType: "sensor",
			// 		timeOrder: "desc",
			// 		hasValue: true,
			// 		productModel: state.productList.join(",")
			// 	},
			// 	true
			// );
			state.imgList = [];
		};
		return () => {
			return (
				<>
					{props.eventInfo.remark == EVENT_AI ? (
						<div class="h-full">
							<div class="ai-img w-96">
								{state.aiInfo.image?.map((item: any, index: number) => {
									return (
										<el-image
											class="w-full"
											fit="fill"
											hide-on-click-modal
											lazy
											initial-index={index}
											preview-src-list={state.aiInfo.image.map((item: any) => `${filePrefix()}${item}`)}
											// src={`${filePrefix()}${item}`}
											src={AirConditioner1Img}
										/>
									);
								})}
							</div>
							<div class="ai-info pt-4">
								<div class="">{props.eventInfo.devName || props.eventInfo.devSn}</div>
								{state.aiInfo.event &&
									Object.entries(state.aiInfo.event).map(item => {
										return (
											<div class="pt-2">
												<div class="flex items-center">
													<span class="label">时间：</span>
													<span class="value">{dayjs(state.aiInfo.timestamp).format("YYYY-MM-DD HH:mm:ss")}</span>
												</div>
												<div class="flex items-center">
													<span class="label">类型：</span>
													<span class="value">{state.dictMap[item[0]]?.label}</span>
												</div>
												<div class="flex items-center">
													<span class="label">置信度：</span>
													<span class="value">
														{item[1].map(detail => {
															return Array.isArray(detail.probs) ? detail.probs.join("，") : detail.probs;
														})}
													</span>
												</div>
												<div class="flex items-center">
													<span class="label">区域：</span>
													<span class="value">
														{item[1].map(detail => {
															return Array.isArray(detail.area) ? detail.area.join("，") : detail.area;
														})}
													</span>
												</div>
											</div>
										);
									})}
							</div>
						</div>
					) : (
						<div class="event-image-list h-full grid grid-cols-4 gap-2">
							{state.imgList.map((item: any, index: number) => {
								return (
									// <div class="">
									<el-image
										class="w-full"
										fit="fill"
										hide-on-click-modal
										lazy
										initial-index={index}
										preview-src-list={state.imgList.map((item: any) => `${filePrefix()}${item.value.image}`)}
										// src={`${filePrefix()}${item.value.image}`}
										src={AirConditioner1Img}
									/>
									// </div>
								);
							})}
						</div>
					)}
				</>
			);
		};
	}
});
